<template>
    <div class="action-bar f-b-r border">
        <div class="a-b_left f-l-r">
            <!-- 搜索框1(有时间选择器) -->
            <div class="l-search f-l-r" style="margin-right: 1rem;" v-if="actionBarData.inputPlaceholder1">
                <el-date-picker v-model="inputData.input1" type="date" :placeholder="actionBarData.inputPlaceholder1" :size="size" :editable="false" @change="search('1', inputData.input1)"/>
                <div class="s-icon" @click="search('1', inputData.input1)"><svg t="1676982650610" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2793" width="16" height="16"><path d="M756.565333 697.258667c2.133333 1.493333 4.224 3.157333 6.101334 5.12l241.664 241.621333c16.256 16.256 16.512 43.52-0.128 60.16a42.453333 42.453333 0 0 1-60.202667 0.170667l-241.664-241.664a41.429333 41.429333 0 0 1-5.034667-6.101334A424.917333 424.917333 0 0 1 426.666667 853.333333C191.018667 853.333333 0 662.314667 0 426.666667S191.018667 0 426.666667 0s426.666667 191.018667 426.666666 426.666667c0 102.698667-36.266667 196.949333-96.768 270.592zM426.666667 768a341.333333 341.333333 0 1 0 0-682.666667 341.333333 341.333333 0 0 0 0 682.666667z" fill="#cdcdcd" p-id="2794"></path></svg></div>
            </div>
            <!-- 搜索框2 -->
            <div class="l-search f-l-r" style="margin-right: 1rem;" v-if="actionBarData.inputPlaceholder2">
                <div class="s-input"><input type="text" class="border" :placeholder="actionBarData.inputPlaceholder2" v-model="inputData.input2"></div>
                <div class="s-icon" @click="search('2', inputData.input2)"><svg t="1676982650610" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2793" width="16" height="16"><path d="M756.565333 697.258667c2.133333 1.493333 4.224 3.157333 6.101334 5.12l241.664 241.621333c16.256 16.256 16.512 43.52-0.128 60.16a42.453333 42.453333 0 0 1-60.202667 0.170667l-241.664-241.664a41.429333 41.429333 0 0 1-5.034667-6.101334A424.917333 424.917333 0 0 1 426.666667 853.333333C191.018667 853.333333 0 662.314667 0 426.666667S191.018667 0 426.666667 0s426.666667 191.018667 426.666666 426.666667c0 102.698667-36.266667 196.949333-96.768 270.592zM426.666667 768a341.333333 341.333333 0 1 0 0-682.666667 341.333333 341.333333 0 0 0 0 682.666667z" fill="#cdcdcd" p-id="2794"></path></svg></div>
            </div>
            <!-- 搜索框3 -->
            <div class="l-search f-l-r" style="margin-right: 1rem;" v-if="actionBarData.inputPlaceholder3">
                <div class="s-input"><input type="text" class="border" :placeholder="actionBarData.inputPlaceholder3" v-model="inputData.input3"></div>
                <div class="s-icon" @click="search('3', inputData.input3)"><svg t="1676982650610" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2793" width="16" height="16"><path d="M756.565333 697.258667c2.133333 1.493333 4.224 3.157333 6.101334 5.12l241.664 241.621333c16.256 16.256 16.512 43.52-0.128 60.16a42.453333 42.453333 0 0 1-60.202667 0.170667l-241.664-241.664a41.429333 41.429333 0 0 1-5.034667-6.101334A424.917333 424.917333 0 0 1 426.666667 853.333333C191.018667 853.333333 0 662.314667 0 426.666667S191.018667 0 426.666667 0s426.666667 191.018667 426.666666 426.666667c0 102.698667-36.266667 196.949333-96.768 270.592zM426.666667 768a341.333333 341.333333 0 1 0 0-682.666667 341.333333 341.333333 0 0 0 0 682.666667z" fill="#cdcdcd" p-id="2794"></path></svg></div>
            </div>
            <!-- 搜索框4 -->
            <div class="l-search f-l-r" style="margin-right: 1rem;" v-if="actionBarData.inputPlaceholder4">
                <div class="s-input"><input type="text" class="border" :placeholder="actionBarData.inputPlaceholder4" v-model="inputData.input4"></div>
                <div class="s-icon" @click="search('4', inputData.input4)"><svg t="1676982650610" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2793" width="16" height="16"><path d="M756.565333 697.258667c2.133333 1.493333 4.224 3.157333 6.101334 5.12l241.664 241.621333c16.256 16.256 16.512 43.52-0.128 60.16a42.453333 42.453333 0 0 1-60.202667 0.170667l-241.664-241.664a41.429333 41.429333 0 0 1-5.034667-6.101334A424.917333 424.917333 0 0 1 426.666667 853.333333C191.018667 853.333333 0 662.314667 0 426.666667S191.018667 0 426.666667 0s426.666667 191.018667 426.666666 426.666667c0 102.698667-36.266667 196.949333-96.768 270.592zM426.666667 768a341.333333 341.333333 0 1 0 0-682.666667 341.333333 341.333333 0 0 0 0 682.666667z" fill="#cdcdcd" p-id="2794"></path></svg></div>
            </div>
            <!-- 清空搜索框 -->
            <!-- <div class="a-b_right" style="height: unset;" v-if="actionBarData.inputPlaceholder4"> -->
            <div class="a-b_right" style="height: unset;" v-if="actionBarData.inputPlaceholder1 || actionBarData.inputPlaceholder2 || actionBarData.inputPlaceholder3 || actionBarData.inputPlaceholder4">
                <div class="r-add" @click.prevent="clearInput"><button>清空搜索框</button></div>
            </div>
        </div>
        <div class="a-b_right f-r-r" v-if="actionBarData.addButtonMsg !== ''">
            <!-- 添加按钮 -->
            <div class="r-add">
                <button @click="addMsg()">
                    <svg t="1676983931150" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4033" width="16" height="16"><path d="M512 73.142857c241.371429 0 438.857143 197.485714 438.857143 438.857143s-197.485714 438.857143-438.857143 438.857143-438.857143-197.485714-438.857143-438.857143 197.485714-438.857143 438.857143-438.857143m0-73.142857C226.742857 0 0 226.742857 0 512s226.742857 512 512 512 512-226.742857 512-512-226.742857-512-512-512z" p-id="4034" fill="#ffffff"></path><path d="M512 219.428571c-21.942857 0-36.571429 14.628571-36.571429 36.571429v512c0 21.942857 14.628571 36.571429 36.571429 36.571429s36.571429-14.628571 36.571429-36.571429v-512c0-21.942857-14.628571-36.571429-36.571429-36.571429z" p-id="4035" fill="#ffffff"></path><path d="M768 475.428571h-512c-21.942857 0-36.571429 14.628571-36.571429 36.571429s14.628571 36.571429 36.571429 36.571429h512c21.942857 0 36.571429-14.628571 36.571429-36.571429s-14.628571-36.571429-36.571429-36.571429z" p-id="4036" fill="#ffffff"></path></svg>
                    {{ actionBarData.addButtonMsg }}
                </button>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { clearObject } from '@/utils/util'
import { toRefs, ref, reactive, onMounted } from 'vue'

const props = defineProps({
    actionBarData: {
        type: Object,
        default: function() {
            return {
                type: {
                    type: Number,
                    default: 0
                },
                addButtonMsg: {
                    type: String,
                    default: ''
                },
                inputPlaceholder1: {
                    type: String,
                    default: ''
                },
                inputPlaceholder2: {
                    type: String,
                    default: ''
                },
                inputPlaceholder3: {
                    type: String,
                    default: ''
                },
                inputPlaceholder4: {
                    type: String,
                    default: ''
                }
            }
        }
    }
})
const { actionBarData } = toRefs(props)

// 日期选框数据
const size = ref<'default' | 'large' | 'small'>('default')
// const time = ref('')
const inputData = reactive({
    input1: '',
    input2: '',
    input3: '',
    input4: ''
})

const emits = defineEmits(['search', 'addMsg', 'clearInput'])

// 搜索
const search = (type:string, value: string) => {
    emits('search', type, value)
}

// 点击添加按钮
const addMsg = () => {
    emits('addMsg')
}

// 清空搜索框
const clearInput = () => {
    Object.assign(inputData, clearObject(inputData))
    emits('clearInput')
}

</script>

<style lang="less" scoped>
.action-bar {
    width: 100%;
    height: 4rem;
    background-color: var(--pc-bg-white);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    .a-b_left, .a-b_right {
        height: 100%;
    }
    .a-b_left {
        .l-search {
            max-width: 13rem;
            position: relative;
            .s-input {
                width: 100%;
                input {
                    width: 100%;
                    height: 2rem;
                    line-height: 2rem;
                    padding: 0 0.5rem;
                    padding-right: 1.5rem;
                    border-radius: 0.3rem;
                    border: 1px solid var(--pc-border-gray);
                }
            }
            .s-icon {
                position: absolute;
                right: 5px;
                cursor: pointer;
            }
        }
    }
    .a-b_right {
        width: auto;
        .r-add {
            width: 7rem;
            height: 2rem;
            button {
                width: 100%;
                height: 100%;
                border-radius: 0.5rem;
                cursor: pointer;
                border: none;
                background-color: var(--pc-button);
                color: #fff;
            }
        }
    }
}

:deep(.el-input) {
    position: relative;
    border: none;
    .el-input__wrapper.focus {
        box-shadow: none;
    }
    .clear-icon {
        position: absolute;
        right: 1.5rem;
    }
}
</style>